#!/bin/bash

echo "$(basename $j .dat)"

echo "Defining Parameters..."
cat data/parameters.dat | grep xsize > temp
sed -i "s/\txsize//g" temp
xsize=$(sed "s/\#//g" temp)
echo "...xsize=$xsize"
cat data/parameters.dat | grep ysize > temp
sed -i "s/\tysize//g" temp
ysize=$(sed "s/\#//g" temp)
echo "...ysize=$ysize"
cat data/parameters.dat | grep steps > temp
sed -i "s/\tsteps//g" temp
steps=$(sed "s/\#//g" temp)
echo "...steps=$steps"
cat data/parameters.dat | grep minhight > temp
sed -i "s/\tminhight//g" temp
minhight=$(sed "s/\#//g" temp)
echo "...minhight=$minhight"
cat data/parameters.dat | grep maxhight > temp
sed -i "s/\tmaxhight//g" temp
maxhight=$(sed "s/\#//g" temp)
echo "...maxhight=$maxhight"
cat data/parameters.dat | grep minshadow > temp
sed -i "s/\tminshadow//g" temp
minshadow=$(sed "s/\#//g" temp)
echo "...minshadow=$minshadow"
cat data/parameters.dat | grep maxshadow > temp
sed -i "s/\tmaxshadow//g" temp
maxshadow=$(sed "s/\#//g" temp)
echo "...maxshadow=$maxshadow"

rm temp
rm -r data/Slab_Hight/*

mkdir data/Slab_Hight
mkdir data/mov

echo "Plotting height for time steps..."
for i in data/raw/hight*.dat; do

#echo "$(basename $i .dat)"
   	gnuplot << EOF
   	set terminal png
   	set output "data/Slab_Hight/pic-$(basename $i .dat).png"
   	unset key
	set grid 
  	set size ratio -1


   	set cbrange [$minhight:$maxhight]
   	set xrange [0:$xsize]
   	set yrange [0:$ysize]
   	plot "$i" binary array=($xsize,$ysize) format="%float" with image
EOF
done

mencoder mf://data/Slab_Hight/pic-hight*.png -mf fps=5:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2 -o data/mov/movhight.avi >/dev/null

